package com.fulihui.wgj.service.miniapp;

import com.alibaba.dubbo.config.annotation.Service;
import com.fulihui.common.builder.rpc.RpcResultBuilder;
import com.fulihui.common.conv.BeanConv;
import com.fulihui.wgj.dal.mybatis.domain.MiniProgramBasicInfo;
import com.fulihui.wgj.dal.mybatis.repository.MiniProgramBasicInfoRepository;
import com.fulihui.wgj.facade.dto.MiniProgramBasicDTO;
import com.fulihui.wgj.facade.result.miniapp.MiniProgramBasicResult;
import com.fulihui.wgj.facade.service.miniapp.MiniAppBasicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @author: Levon
 * @date: 2018-07-26 13:48
 */
@Component
@Service(interfaceClass = MiniAppBasicService.class, version = "1.0.0")
public class MiniAppBasicServiceImpl implements MiniAppBasicService {

    @Autowired
    private MiniProgramBasicInfoRepository miniProgramBasicInfoRepository;

    /**
     * 查询小程序列表：用户模板推送选择小程序列表
     *
     * @return 返回小程序基本信息
     */
    @Override
    public MiniProgramBasicResult queryMiniProgramList() {
        List<MiniProgramBasicInfo> basicInfos = miniProgramBasicInfoRepository.queryAll();
        MiniProgramBasicResult result = RpcResultBuilder.succ(MiniProgramBasicResult.class);
        if (!CollectionUtils.isEmpty(basicInfos)) {
            result.setValues(BeanConv.copy(basicInfos, MiniProgramBasicDTO.class));
        }
        return result;
    }
}
